package reservator.common;

import java.io.Serializable;

/**
 * Represent a client of the reservator system
 * @author Pascal Cuisinaud, Thomas Di'Meco
 */
public class Client implements Serializable
{
    private static final long serialVersionUID = 1L;
    
    private int    id;
    private String firstName;
    private String lastName;
    
    /**
     * Default constructor
     */
    public Client () {}
    
    /**
     * Construct a client with the given informations
     * @param id        The client id
     * @param firstName The client first name
     * @param lastName  The client last name
     */
    public Client (int id, String firstName, String lastName)
    {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }
    
    /**
     * Equals method for Client
     * @param object to be checked
     * @return true if object equals this Client, false otherwise
     */
    @Override
    public boolean equals (Object obj)
    {
        if (this == obj) return true;
        if (!(obj instanceof Client)) return false;
        
        Client other = (Client) obj;
        
        return (this.id == other.id) &&
               this.firstName.equals(other.firstName) &&
               this.lastName.equals(other.lastName);
    }
    
    /**
     * ToString method
     * @return A string that contains the class intance's informations
     */    
    @Override
    public String toString ()
    {
        return "Client [id=" + id + ", firstName=" + firstName + ", lastName="
                + lastName + "]";
    }
    
    /**
     * Create a Client from a String which contains client informations. (reverse of toString())
     * @param A string that contains the class intance's informations
     */    
    public void createClient (String s)
    {
        // extracting data from the string and use setters to put it in the
        // client
        setId(Integer.valueOf(s.split(",")[0].split("=")[1]));
        setFirstName(s.split(",")[1].split("=")[1]);
        setLastName(s.split(",")[2].split("=")[1].split("]")[0]);
    }

    // ************* Getters and Setters *************
    public int getId ()
    {
        return id;
    }

    public void setId (int id)
    {
        this.id = id;
    }

    public String getFirstName ()
    {
        return firstName;
    }

    public void setFirstName (String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName ()
    {
        return lastName;
    }

    public void setLastName (String lastName)
    {
        this.lastName = lastName;
    }
    // **********************************************
    

}
